home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
yerk
/
mps231ss.hqx
/
Mops source
/
Toolbox classes
/
interval timer
< prev
next >
Wrap
Text File
|
1993-02-01
|
1KB
|
49 lines
\ interval - interval timer stuff
\ 12/14/84 cbd Version 1
\ 10/15/85 cdn Fixed print: method in Timer
\ 1/31/87 rfl added clear:
\ 6/13/89 rfl added pause
\ ***Not converted to Mops yet.
Decimal
\ define an interval timer class
:CLASS Timer <Super Object
Var Ticks \ store system ticks=60ths
Int On \ true = timing
\ ( -- ticks ) update the system event record and return its time
:M WHEN: ?terminal drop when: fEvent ;M
\ start timing an interval
:M START: when: self put: ticks 1 put: on ;M
\ stop the clock, and replace ticks with the interval
:M STOP: when: self get: ticks - put: ticks clear: on ;M
\ ( -- secs*60 ) get the current value of the clock, but keep timing if on
:M GET: get: on
IF when: self get: ticks -
ELSE get: ticks THEN ;M
\ print the current value of the timer, in seconds and hundredths
:M PRINT: get: self 60 /mod 3 .R $ 2e emit 100 * 60 /
2 .R ." Seconds " ;M
:M CLEAR: clear: on clear: ticks ;M
;CLASS
Timer sysTimer \ create an instance of Timer
\ ( -- f OR key t ) listen to event queue, true if key event
: ?Key next: fEvent ;
\ general purpose pause where time is in 1/60ths of second
timer pTimer
: pause { time -- } start: pTimer
BEGIN next: fevent IF 2drop THEN get: pTimer time > UNTIL ;